# SPDX-FileCopyrightText: 2025 MounRiver Studio <https://mounriverstudio.com/>
# SPDX-License-Identifier: BSD-3-Clause
# Author: Azolla <https://gitee.com/azolla/>
# Date: 2025-04-21

# 设置CMake版本
cmake_minimum_required(VERSION 3.16)

# 设置FreeRTOS开关
set(CONFIG_FREERTOS ON CACHE BOOL "Compile FreeRTOS") 

# Include toolchain file
include(${CMAKE_CURRENT_SOURCE_DIR}/../../components/cmake/ch32v.cmake)
 
# 项目名称和语言
set(PROJECT_AUTHOR "Azolla")
project("myProject" VERSION 1.0.0 LANGUAGES C ASM)
message(STATUS "${G}Project: ${PROJECT_NAME}${E}")
message(STATUS "${G}Version: ${PROJECT_VERSION}${E}")
message(STATUS "${G}Author:  ${PROJECT_AUTHOR}${E}")

# 解析 prj.conf 文件生成 prjconf.h 文件
add_command_prj2conf()  # 注意：放在 project() 之后
 
# Create an executable object type
add_executable(${PROJECT_NAME}
    app_main.c
    ch32v20x_it.c
)

# 添加头文件包含目录，这里假设头文件在当前目录下
target_include_directories(${PROJECT_NAME} PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}/
    ${CMAKE_CURRENT_BINARY_DIR}/include  # 包含 build 目录头文件
)
 
# 添加链接库
target_link_libraries(${PROJECT_NAME} PRIVATE driver utils hal)
if(CONFIG_FREERTOS)
    target_link_libraries(${PROJECT_NAME} PRIVATE FreeRTOS)
endif()

# 添加全局宏定义
add_definitions(
    -DCH32V208=1
    -DSYSCLK_FREQ_144MHz_HSE=144000000
    -DDEBUG=DEBUG_UART2
)

# 最后设置链接脚本
target_link_compile_options(${PROJECT_NAME})
